package rank1400;

/**
 * 1588. 所有奇数长度子数组的和
 */
public class No1588 {
    public int sumOddLengthSubarrays(int[] arr) {
        int ans = 0;
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            int preSum = arr[i];
            ans += preSum;
            for (int j = i + 2; j < n; j += 2) {
                preSum += arr[j] + arr[j - 1];
                ans += preSum;
            }
        }
        return ans;
    }
}
